<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员列表</title>
    <link rel="stylesheet" href="/plugins/element-ui/index.css">
    <style>
        .tableBar {
            display: flex;
            justify-content: space-between;
        }
        .tableBox {
            margin-top: 20px;
            margin-bottom: 20px;
            border-bottom: solid 2px #f3f4f7;
            border-top: solid 2px #f3f4f7;
        }
        .pageList {
            display: flex;
            justify-content: center;
        }
        .non {
            color: red;
        }
    </style>
</head>
<body>
<div class="dashboard-container" id="member-app">
    <div class="container">
        <div class="tableBar">
            <el-input
                    v-model="input"
                    placeholder="请输入用户姓名"
                    style="width: 250px"
                    clearable
                    @keyup.enter.native="handleQuery">
                <i
                        slot="prefix"
                        class="el-input__icon el-icon-search"
                        style="cursor: pointer"
                        @click="handleQuery">
                </i>
            </el-input>
            <!--<el-button-->
            <!--        type="primary"-->
            <!--        @click="addUserHandle('add')">-->
            <!--    + 添加用户-->
            <!--</el-button>-->
        </div>
        <el-table
                :data="tableData"
                stripe
                size="mini"
                class="tableBox">
            <el-table-column
                    prop="username"
                    label="用户账号"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="headerImg"
                    label="头像"
                    align="center">
                <template slot-scope="scope">
                    <el-avatar :size="40" :src="getImage(scope.row.headerImg)"></el-avatar>
                </template>
            </el-table-column>
            <el-table-column
                    prop="sex"
                    label="性别"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="wechat"
                    label="微信"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="phone"
                    label="手机号"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="member"
                    label="会员等级"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="integral"
                    label="会员积分"
                    align="center">
            </el-table-column>
            <!--<el-table-column-->
            <!--        label="操作"-->
            <!--        width="200"-->
            <!--        align="center">-->
            <!--    <template slot-scope="scope">-->
            <!--        <el-button-->
            <!--                type="text"-->
            <!--                size="small"-->
            <!--                class="blueBut"-->
            <!--                @click="addUserHandle(scope.row.userId)">-->
            <!--            编辑-->
            <!--        </el-button>-->
            <!--        <el-button-->
            <!--                type="text"-->
            <!--                size="small"-->
            <!--                class="delBut non"-->
            <!--                @click="removeHandle(scope.row.userId)">-->
            <!--            删除-->
            <!--        </el-button>-->
            <!--    </template>-->
            <!--</el-table-column>-->
        </el-table>
        <el-pagination
                class="pageList"
                :page-size="pageSize"
                layout="total, prev, pager, next, jumper"
                :total="counts"
                :current-page.sync="page"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange">
        </el-pagination>
    </div>
</div>

<script src="/plugins/vue/vue.js"></script>
<script src="/plugins/element-ui/index.js"></script>
<script src="/plugins/axios/axios-0.18.0.js"></script>
<script src="/js/member.js"></script>
<script>
    new Vue({
        el: '#member-app',
        data() {
            return {
                input: '',
                counts: 0,
                page: 1,
                pageSize: 5,
                tableData : [],
                id: '',
            }
        },
        methods: {
            init() {
                const params = {
                    pageNum: this.page,
                    pageSize: this.pageSize,
                    username: this.input ? this.input : undefined,
                }
                axios.get('/user/query', {params}).then(res => {
                    let info = res.data
                    if (info.code === 1) {
                        this.tableData = info.data.records || []
                        this.counts = info.data.total
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            // 查询
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 添加、修改
            addUserHandle (st) {
                if (st === 'add'){
                    window.location.href = '/page/user/add.html'
                } else {
                    window.location.href = '/page/user/add.html?id=' + st
                }
            },
            // 删除
            removeHandle(id) {
                this.$confirm("确认删除？", "提示", {type: "warning"}).then(() => {
                    axios.delete('/user/' + id).then(res => {
                        let info = res.data
                        if (info.code === 1) {
                            this.init()
                            this.$message.success('用户删除成功！')
                        } else {
                            this.$message.error('用户删除失败！')
                        }
                    })
                })
            },
            getImage (image) {
                return `/common/download?fileName=${image}`
            },
            handleSizeChange (val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange (val) {
                this.page = val
                this.init()
            }
        },
        created() {
            this.init()
        },
    })
</script>
</body>
</html>
